<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>经营报表</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
		<style>
			.btn_qr{
				margin:10px;
				
				padding: 3px;
				width: 100px;
				bottom: 10px;
			}
		</style>
	</head>

	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<div class="sy_logobox">
						<div class="sy_logo"><img src="img/logo-ma.png"></div>
						<p id="app_name"></p>
					</div>
					<ul class="sy_nav clearfix">
						<li>
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>桌台点餐</p>
							</a>
						</li>
						<li class="active">
							<a href="reserve.html">
								<div class="iconfont icon-saomashouyin"></div>
								<p>预订管理</p>
							</a>
						</li>
						<li>
							<a href="deal_order.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>交易查询</p>
							</a>
						</li>
						<li>
							<a href="xiaof_member.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>会员管理</p>
							</a>
						</li>
						<li>
							<a href="jiaoban.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>交班</p>
							</a>
						</li>
					</ul>
				</div>
				<div class="sy_shopbox">
					<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
					<div class="sy_sinfo">
						<p class="sy_snam">店名：<span id="sname"></span></p>
						<p>用户：<span id="user">15973240090</span></p>
						<p class="exit" onclick="exit()">退出登陆</p>
					</div>
				</div>
			</div>

			<div class="sy_xconbox clearfix">
				<div class="sy_xftop clearfix">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">订单号</label>
							<div class="layui-input-inline">
								<input type="text" id="sn" placeholder="请输入订单号" name="sn" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">交易时间</label>
							<div class="layui-input-inline" style="width: 120px;">
								<input  ignore type="text" placeholder="yyyy-mm-dd" name="date" id="start_time" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">-</div>
							<div class="layui-input-inline" style="width: 120px;">
								<input  ignore type="text" placeholder="yyyy-mm-dd" name="date1" id="end_time" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="button" id="search" class="sy_jybtn">搜索</button>
						</div>

					</div>
				</div>
				<div class="sy_spcenter">
					<table class="layui-table">
						<colgroup>
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>类型</th>
								<th>状态</th>
								<th>预定人</th>
								<th>电话</th>
								<th>到店时间</th>
								<th>人数</th>
								<th>桌台</th>
								<th>订单金额</th>
								<th width="150">操作</th>
							</tr>
						</thead>
						<tbody id="mem_body">
						</tbody>
					</table>
					<div id="demo2" style="text-align: center;"></div>
				</div>
			</div>
		</div>
			<div class="jjbbp_conbox" style="display: none;">
			<div class="jjbbp_item">
				<div class="jjbbp_bt">预定信息</div>
				<ul class="jjbbp_list clearfix">
					<li>
						<span class="bt">订单号：</span>
						<span id="order_sn" class="nr"></span>
					</li>
					<li>
						<span class="bt">下单时间：</span>
						<span id="add_time" class="nr"></span>
					</li>
					<li>
						<span class="bt">支付时间：</span>
						<span id="pay_time" class="nr"></span>
					</li>
					<li>
						<span class="bt">会员号：</span>
						<span class="nr" id="user_id"></span>
					</li>
					<li>
						<span class="bt">订单金额：</span>
						<span class="nr" id="origin_price"></span>
					</li>
					<li>
						<span class="bt">支付金额：</span>
						<span class="nr" id="pay_price"></span>
					</li>
					<li>
						<span class="bt">支付方式：</span>
						<span class="nr" id="pay_type"></span>
					</li>
					<li>
						<span class="bt">会员优惠券：</span>
						<span class="nr" id="member_score"></span>
					</li>
					<li>
						<span class="bt">商家优惠券：</span>
						<span class="nr" id="agent_score"></span>
					</li>
				</ul>
			</div>
			<div class="jjbbp_item2">
				<div class="jjbbp_bt">商品信息</div>
				<div class="jjbbp_table">
					<table class="layui-table">
						<colgroup>
							<col width="39%">
							<col width="15%">
							<col width="10%">
							<col width="12%">
							<col width="12%">
							<col width="12%">
						</colgroup>
						<thead>
							<tr>
								<th>商品</th>
								<th>数量</th>
								<th>小计</th>
							</tr>
						</thead>
						<tbody id="goods_tr">
					
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="jjbbp_conbox" style="display: none;">
		</div>
		<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
		<script src="dist/layui.all.js"></script>
		<script src="dist/json2.js"></script>
		<script src="datepicker/WdatePicker.js"></script>
		<script type="text/javascript" src="js/app.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script>
			function opnetai (reserve_id){
						$.ajax({
						url: APP.api_url + "Sy/get_dinners",
						data: {
							store_id: getValue("store_name_id")
						},
						success: function(data) {
							var list = data.list;
							if(list) {
								var tr = "";
								var html='<div><ul class="fant_list clearfix">';
								for(var m in list) {
									var log = list[m];
									html+='<li  data-dinner_id="2"  style="cursor: pointer;" onclick=open_dinner('+log["id"]+','+reserve_id+',1) >'+
											'<div class="fantnambox clearfix">'+
											'<span class="fantnam">桌台号:'+log['dinner_name']+'</span><span class="fanttype">开</span></div>'+
											'<div class="fantpri">#2</div><div class="fantnumbox clearfix">'+
											'<span class="fanttime">5</span>人<span class="fantnum">限5人</span></div></li>';
								}
								html+='</ul></div>';
								layer.open({
										title: '开台',
										shadeClose: false,
										shade: 0.8,
										btn: false,
										area: ['750px', '650px'],
										content: html
								});
								
							}
						}
					})
		
						
			}
			if(!getValue("store_name_id")) {
				location.href = 'login.html';
			}
			$(function() {
				set_info();
				load_dt();
			})
			$("#search").click(function() {
				var mobile = $("#mobile").val();
				var start_time = $("#start_time").val();
				var end_time = $("#end_time").val();
				load_dt(1, mobile, start_time, end_time)

			})
			
			$("#export").click(function() {
				var begin = $("#start_time").val();
				var end = $("#end_time").val();
				var str = "&begin_time=" + begin + "&end_time=" + end;
				window.location.href = APP.api_url + "sy/export?chain_id=" + getValue("chain_id") + str;
			})
			
			//开关台
			function open_dinner(dinner_id,reserve_id,type){
				layer.confirm('确定开台?', function(index) {
			        $.ajax({
				          url:APP.api_url + "sy/reserve_opent",
				          data:{
				          		dinner_id:dinner_id,
				          		reserve_id:reserve_id,
				          		type:type
				          },
				          success:function(data) {
							layer.msg(data.msg, {
							}, function(){
							  	window.parent.location.reload();
								var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
					       		parent.layer.close(index); 
							});   
				          }
				        })
			      })
			}
			
			
			function load_dt(page, mobile, start_time, end_time) {
				layui.use(['laypage', 'layer'], function() {
					var laypage = layui.laypage,
						layer = layui.layer;
					var index = layer.load(1, {
						shade: [0.1, '#fff'] //0.1透明度的白色背景
					});
					$.ajax({
						url: APP.api_url + "Sy/reserve_list",
						data: {
							store_id: getValue("store_name_id"),
							page: page,
							mobile: mobile,
							start_time: start_time,
							end_time: end_time,
							app_id	:APP.app_id,
							time:Date.parse( new Date())
						},
						success: function(data) {
							var mems = data.reserve_list;
							var count = data.count;
							if(mems) {
								var tr = "";
								for(var m in mems) {
									var log = mems[m];
									var type = "公众号";
									if(log['user_id']>0) {
										type = '电话';
									} 
									
									var status = "待处理";
									if(log.state == 1){
										status = "待支付";
									}else if(log.state == 2){
										status = "已支付";
									}else if(log.state == 3){
										status = "已受理待点餐 ";
									}else if(log.state == 4){
										status = "已清台";
									}
									
									var room_id = 0
									if(log['room_id']){
										room_id = log['room_id'];
									}
									
									tr += '<tr>' +
										'<td>' + type + '</td>' +
										'<td>' + status + '</td>' +
										'<td>' + log['user_name'] + '</td>' +
										'<td>' + log['mobile'] + '</td>' +
										'<td>' + log['jc_time'] + '</td>' +
										'<td>' + log['room_num'] + '</td>' +
										'<td>' + room_id + '</td>' +
										'<td>' + log['origin_price'] + '</td>' +
										'<td>'+
										'<a href="javascript:opnetai('+log['id']+')" class="layui-btn layui-btn-mini" lay-event="edit">开台</a>'+
										'<a href="javascript:open_dinner('+log['room_id']+','+log['id']+',2)" class="layui-btn layui-btn-mini" lay-event="edit">取消</a>'+
										'</td></tr>';
								}
								$("#mem_body").html(tr);
								layer.close(index);
								//调用分页
								laypage.render({
									elem: 'demo2',
									count: count,
									limit: 7,
									jump: function(obj, first) {
										//模拟渲染
										var curr = obj.curr;
										if(!first) {
											get_reports(curr);
										}
									}
								});
							}
						}
					})
				});
			}

			function get_reports(page) {
				$.ajax({
					url: APP.api_url + "Sy/reserve_list",
						data: {
							store_id: getValue("store_name_id"),
							page: page,
							mobile: $("#mobile").val(),
							start_time:$("#start_time").val(),
							end_time:$("#end_time").val(),
							app_id	:APP.app_id,
							time:Date.parse( new Date())
						},
					success: function(data) {
						var mems = data.reserve_list;
							var count = data.count;
							if(mems) {
								var tr = "";
								for(var m in mems) {
									var log = mems[m];
									var type = "公众号";
									if(log['user_id']>0) {
										type = '电话';
									} 
									
									var status = "待处理";
									if(log.state == 1){
										status = "待支付";
									}else if(log.state == 2){
										status = "已支付";
									}else if(log.state == 3){
										status = "已受理待点餐 ";
									}else if(log.state == 4){
										status = "已清台";
									}
									
									
									tr += '<tr>' +
										'<td>' + type + '</td>' +
										'<td>' + status + '</td>' +
										'<td>' + log['user_name'] + '</td>' +
										'<td>' + log['mobile'] + '</td>' +
										'<td>' + log['jc_time'] + '</td>' +
										'<td>' + log['room_num'] + '</td>' +
										'<td>' + room_id + '</td>' +
										'<td>' + log['origin_price'] + '</td>' +
										'<td>'+
										'<a href="javascript:opnetai('+log['id']+')" class="layui-btn layui-btn-mini" lay-event="edit">开台</a>'+
										'<a href="javascript:open_dinner('+log['room_id']+','+log['id']+',2)" class="layui-btn layui-btn-mini" lay-event="edit">取消</a>'+
										'</td></tr>';
								}
							$("#mem_body").html(tr);
						}
					}
				})
			}
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
				//日期
				laydate.render({
					elem: '#start_time'
				});
				laydate.render({
					elem: '#end_time'
				});

			});
			
		</script>
	</body>
</html>